package com.cgi.ndk.wf.soa;

import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.client.core.SoapActionCallback;

/**
 *
 * @author kovalcikm
 */
public class SoaClient extends WebServiceGatewaySupport {

    public Object geResponse(Object obj, String uri, String action, String contextPath) {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath(contextPath);

        this.setMarshaller(marshaller);
        this.setUnmarshaller(marshaller);

        WebServiceTemplate template = getWebServiceTemplate();
        template.setMessageSender(new WebServiceMessageSenderWithAuth());
        this.setDefaultUri(uri);

        Object response = template.marshalSendAndReceive(
                obj,
                new SoapActionCallback(
                        action));

        return response;
    }
}
